package com.ssyan.principle.DependenceInversion.improve;

/**
 * @author ssyan
 * @Description 七大设计原则之三：依赖倒转原则
 * @create 2021/8/25 22:47
 * @Version 1.0
 */
public class DependencyInversion {

    public static void main(String[] args) {
        Person person = new Person();
        person.receive(new Email());
        person.receive(new WeiXin());
    }
}

//定义接口
interface IReceiver {
    public String getInfo();
}

class Email implements IReceiver{
    public String getInfo() {
        return "电子邮件信息：hello,world";
    }
}

//增加微信
class WeiXin implements IReceiver{

    @Override
    public String getInfo() {
        return "微信信息：hello，ok";
    }
}

//方式2
class Person {
    //这里我们是对接口的依赖，稳定性强
    public void receive(IReceiver receiver) {
        System.out.println(receiver.getInfo());
    }
}
